### must use go >= 1.19

TARGET_DIR=dist
APP=gscdatasets

# Go parameters
GOCMD=GO111MODULE=on go
GOGEN=$(GOCMD) generate
GOBUILD=$(GOCMD) build
GODOWNLOAD=$(GOCMD) mod download

# DB
DB_SCHEMA_SOURCE=$HOME/golang/biling-dber/migration/gsc-datasets/
DB_SCHEMA_TO=internal/db/migration

env:
	echo "shell exec => gvm use go1.19.9"

sch:
	ln -s $(DB_SCHEMA_SOURCE) $(DB_SCHEMA_TO)

sqlc:
	sqlc generate

dev:
	go run cmd/main.go


download:
	$(GODOWNLOAD)

gen:
	$(GOGEN) ./...

build:
	rm -rf $(TARGET_DIR)
	mkdir -p $(TARGET_DIR)
	#cp conf/config.toml $(TARGET_DIR)/config.toml
	$(GOBUILD) -o $(TARGET_DIR)/$(APP) cmd/main.go


#build for stage
stage=dev
# tecent scf server_url
server_url="ccr.ccs.tencentyun.com"
# 命名空间
namespace="tool.originforce"
# 镜像名称
image_name="gsc-datasets"
# 镜像版本
tag_name="latest"
# 镜像地址
image_url=$(server_url)/$(namespace)/$(image_name)-$(stage)

docker-build:
	echo "$(image_url):$(tag_name)"
	docker build -t "$(image_url):$(tag_name)" \
  --build-arg STAGE=$(stage) .

clean:
	rm -rf $(TARGET_DIR)

run:
	nohup $(TARGET_DIR)/$(APP) -c=$(TARGET_DIR)/config.toml 2>&1 > $(TARGET_DIR)/$(APP).log &

stop:
	pkill -f $(TARGET_DIR)/$(APP)
